package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.RoleDto;
import com.zzyl.service.RoleService;
import com.zzyl.vo.RoleVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@Api(tags = "角色管理")
@RestController
@RequestMapping("/role")
public class RoleController {
    @Autowired
    private RoleService roleService;
    @ApiOperation("角色分页查询")
    @PostMapping("/page/{pageNum}/{pageSize}")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "roleDto",value = "角色DTO对象",required = true,dataType = "roleDto"),
            @ApiImplicitParam(paramType = "path",name = "pageNum",value = "页码",example = "1",dataType = "Integer"),
            @ApiImplicitParam(paramType = "path",name = "pageSize",value = "每页条数",example = "10",dataType = "Integer")
    })
      public ResponseResult<PageResponse<RoleVo>> findRoleVoPage(@RequestBody RoleDto roleDto){
        PageResponse <RoleVo> roleVoPage=roleService.findRoleVoPage(roleDto,1,10);
             return ResponseResult.success(roleVoPage);
      }
      //角色添加
    @PostMapping
    @ApiOperation("角色添加")
    public ResponseResult<Boolean> createRole( @RequestBody RoleDto roleDto){

          roleService.createRole(roleDto);

        return ResponseResult.success();

    }
    //角色修改
    @PatchMapping
    @ApiOperation("角色的修改")
    public ResponseResult<Boolean> updateRole(@RequestBody RoleDto roleDto){
        Boolean flag=roleService.updateRole(roleDto);
        return  ResponseResult.success(flag);
    }
    //删除角色
    @DeleteMapping("/{roleId}")
    @ApiOperation("删除角色")
    public ResponseResult delectRole(@PathVariable("roleId") Long roleId) {
        return ResponseResult.success(roleService.deleteRoleById(roleId));
    }
}
